﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartRS.com.vn.smartrs.domain.custom
{
    public class FoodDataRow
    {
        public long stt { get; set; }
        public long foodId { get; set; }
        public string foodName { get; set; }
        public string foodUnitName { get; set; }
        public long price { get; set; }
        public long discountValue { get; set; }
        public IList<FoodDataRow> copyProperties(IList<FoodKind> foodKindList)
        {
            var data = new List<FoodDataRow>();
            foreach (FoodKind fk in foodKindList)
            {
                var temp = copyProperty(fk);
                if(null != temp && temp.Count >0)
                {
                    data.AddRange(temp);
                }
            }
            int count = 0;
            //Order index
            foreach(FoodDataRow fdr in data)
            {
                fdr.stt = ++count;
            }
            return data.Distinct().ToList();
        }
        public IList<FoodDataRow> copyProperty(FoodKind foodKind)
        {
            return copyProperties(foodKind.foodList);
        }
        public IList<FoodDataRow> copyProperties(IList<Food> foodList)
        {
            IList<FoodDataRow> foodDataRowList = new List<FoodDataRow>();
            //list is null or empty
            if (foodList == null || foodList.Count == 0)
            {
                return foodDataRowList;
            }
            int count = 0;
            foreach (Food food in foodList)
            {
                //Convert object
                FoodDataRow foodDataRow = copyProperties(++count, food);
                //add element to list
                foodDataRowList.Add(foodDataRow);
            }


            return foodDataRowList;
        }
        public FoodDataRow copyProperties(int stt,Food food)
        {

            //FoodOrder is null or empty
            if (food == null)
            {
                return new FoodDataRow(); ;
            }

            //Convert object
            FoodDataRow foodDataRow = new FoodDataRow()
            {
                stt = stt,
                foodId = food.foodId,
                foodName = food.foodName,
                price = food.price,
                discountValue = food.discountValue 
               
            };
            if(null != food.foodUnit)
            {
                foodDataRow.foodUnitName = food.foodUnit.foodUnitName;
            }
            else
            {
                foodDataRow.foodUnitName = "";
            }
            return foodDataRow;
        }
    }
}
